package com.ukao.pad.dialog;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ukao.pad.R;
import com.ukao.pad.base.BaseDialogFragment;
import com.ukao.pad.bean.RecheckBean;
import com.ukao.pad.utils.CheckUtils;
import com.ukao.pad.widget.StateButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


public class SetPutawayFragment extends BaseDialogFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.close_btn)
    ImageView closeBtn;
    @BindView(R.id.count_text)
    TextView countText;
    @BindView(R.id.factory_shelfno)
    EditText factoryShelfno;
    @BindView(R.id.sure_btn)
    StateButton sureBtn;
    Unbinder unbinder;

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private RecheckBean mRecheckBean;


    public static SetPutawayFragment newInstance(RecheckBean param1, String param2) {
        SetPutawayFragment fragment = new SetPutawayFragment();
        Bundle args = new Bundle();
        args.putParcelable(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            mRecheckBean =  getArguments().getParcelable(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_set_putaway, container, false);
        unbinder = ButterKnife.bind(this, view);
        countText.setText("第"+mRecheckBean.getProIndex()+"件,共"+mRecheckBean.getProTotal()+"件");
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getDialog().setCanceledOnTouchOutside(false);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.close_btn, R.id.sure_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.close_btn:
                break;
            case R.id.sure_btn:
                String   strFactoryShelfno=getText(factoryShelfno);
                if (!CheckUtils.isEmpty( strFactoryShelfno)){
                    if (mOnConfirmClickListener!=null){
                        mOnConfirmClickListener.onChildItemClick(0,strFactoryShelfno);
                    }
                }


                break;
        }
    }
}
